export function checkobjectkey<T extends string, K extends keyof TypeCheckMap>(
    o: object,
    key: T,
    objecttype: K
): asserts o is Record<T, TypeCheckMap[K]> {
    if (!Object.keys(o).includes(key)) {
        throw Error("object" + o + " has not key " + key);
    }
    const value = Reflect.get(o, key);
    if (objecttype === "string") {
        if (typeof value !== "string") {
            throw new Error(
                "object" + o + " key " + key + "is not " + objecttype
            );
        }
        return;
    }
    if (objecttype === "number") {
        if (typeof value !== "number") {
            throw new Error(
                "object" + o + " key " + key + "is not " + objecttype
            );
        }
        return;
    }
    if (objecttype === "object") {
        if (!(value && typeof value == "object")) {
            throw new Error(
                "object" + o + " key " + key + "is not " + objecttype
            );
        }
        return;
    }
    if (objecttype === "array") {
        if (!Array.isArray(value)) {
            throw new Error(
                "object" + o + " key " + key + "is not " + objecttype
            );
        }
        return;
    }
    if (objecttype === "function") {
        if (typeof value !== "function") {
            throw new Error(
                "object" + o + " key " + key + "is not " + objecttype
            );
        }
        return;
    }
    throw new Error("unknown type " + objecttype);
}

export interface TypeCheckMap {
    function: (...args: any) => any;
    string: string;
    number: number;
    object: Record<string, any>;
    array: Array<any>;
}
